package com.cl.mybatis.learn.day16;

import java.io.InputStream;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.cl.mybatis.learn.day16.bean.User;
import com.cl.mybatis.learn.day16.dao.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


public class Mybatis001 {
    public static void main(String[] args) throws Exception {
        
        String resource = "common1/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        UserMapper mapper = session.getMapper(UserMapper.class);

        
        try {
            List<User> users = mapper.selectAll();
            Object obj = JSONArray.toJSON(users);
            String json = obj.toString();
            System.out.println("users：" + json);
        } finally {
            session.close();
        }
        
    }
    
}
